package com.mervin.helper;

import com.mervin.annotation.LineFieldAnnotation;

import java.lang.reflect.Field;

/***************************************
 * @author: mervin
 * @Date: 2020-05-04 13:08
 * @Description: 特定分隔符的处理类
 ***************************************/
public class SeparateParseProcess extends ParseProcess {

    @Override
    protected String getFieldStrVal(Field field, String line) {
        String[] lineArray = line.split("\\|");
        int index = getFieldIndex(field);
        if(index > lineArray.length -1){
            return "";
        }
        return lineArray[index];
    }

    private int getFieldIndex(Field field){
        LineFieldAnnotation fieldAnnotation = field.getAnnotation(LineFieldAnnotation.class);
        return fieldAnnotation.index();
    }
}
